package bvethWin

import (
	"bveth"
	"github.com/lxn/walk"
	. "github.com/lxn/walk/declarative"

	// "os"
	// "strings"
	// "time"

	"jk/jklog"
	// "strconv"
)

type bvethListWindow struct {
	*walk.MainWindow
	startDebug  *walk.PushButton
	stopDebug   *walk.PushButton
	more        *walk.PushButton
	customInput *walk.TextEdit
	curDevice   bveth.DeviceInfo
}

func (bv *bvethListWindow) sendRequest() {
	v := bv.customInput.Text()
	// bveth.JKControlCommonExtString(bv.curDevice.MacAddr, bv.curDevice.IpAddr, 6000, len(v), v)
	walk.MsgBox(bv, "警告", "目前还不支持-.- "+v, walk.MsgBoxOK)

}

func bvethListWindowStart(parent walk.Window, curDevice bveth.DeviceInfo) {
	mw := new(bvethListWindow)

	mw.curDevice = curDevice

	main := MainWindow{
		AssignTo: &mw.MainWindow,
		Title:    curDevice.Name,
		MinSize:  Size{300, 520},
		Layout:   VBox{},
		Children: []Widget{
			PushButton{
				AssignTo: &mw.startDebug,
				Text:     "打开misc_ctrl调试打印",
				OnClicked: func() {
					bveth.JKControlCommon(mw.curDevice.MacAddr, mw.curDevice.IpAddr, bveth.BV_OPEN_MISC_CTRL_DEBUG)
				},
			},
			PushButton{
				AssignTo: &mw.stopDebug,
				Text:     "关闭misc_ctrl调试打印",
				OnClicked: func() {
					bveth.JKControlCommon(mw.curDevice.MacAddr, mw.curDevice.IpAddr, bveth.BV_CLOSE_MISC_CTRL_DEBUG)
				},
			},
			PushButton{
				AssignTo: &mw.more,
				Text:     "打开misc_ctrl循环打印",
				OnClicked: func() {
					bveth.JKControlCommon(mw.curDevice.MacAddr, mw.curDevice.IpAddr, bveth.BV_OPEN_MISC_CTRL_CYCLE)
				},
			},
			PushButton{
				AssignTo: &mw.more,
				Text:     "关闭misc_ctrl循环打印",
				OnClicked: func() {
					bveth.JKControlCommon(mw.curDevice.MacAddr, mw.curDevice.IpAddr, bveth.BV_CLOSE_MISC_CTRL_CYCLE)
				},
			},
			PushButton{
				AssignTo: &mw.more,
				Text:     "打开livecams调试打印",
				OnClicked: func() {
					bveth.JKControlCommon(mw.curDevice.MacAddr, mw.curDevice.IpAddr, bveth.BV_OPEN_LIVECAMS_LOG)
				},
			},
			PushButton{
				AssignTo: &mw.more,
				Text:     "关闭livecams调试打印",
				OnClicked: func() {
					bveth.JKControlCommon(mw.curDevice.MacAddr, mw.curDevice.IpAddr, bveth.BV_CLOSE_LIVECAMS_LOG)
				},
			},
			PushButton{
				AssignTo: &mw.more,
				Text:     "禁用重启",
				OnClicked: func() {
					bveth.JKControlCommon(mw.curDevice.MacAddr, mw.curDevice.IpAddr, bveth.BV_DISABLE_REBOOT)
				},
			},
			PushButton{
				AssignTo: &mw.more,
				Text:     "启用重启",
				OnClicked: func() {
					bveth.JKControlCommon(mw.curDevice.MacAddr, mw.curDevice.IpAddr, bveth.BV_ENABLE_REBOOT)
				},
			},
			PushButton{
				AssignTo: &mw.more,
				Text:     "禁用调试串口",
				OnClicked: func() {
					bveth.JKControlCommon(mw.curDevice.MacAddr, mw.curDevice.IpAddr, bveth.BV_CLOSE_CONSOLE)
				},
			},
			PushButton{
				AssignTo: &mw.more,
				Text:     "启用调试串口",
				OnClicked: func() {
					bveth.JKControlCommon(mw.curDevice.MacAddr, mw.curDevice.IpAddr, bveth.BV_OPEN_CONSOLE)
				},
			},
			TextEdit{
				AssignTo: &mw.customInput,
				// ReadOnly: true,
			},
			PushButton{
				AssignTo:  &mw.more,
				Text:      "自定义命令",
				OnClicked: mw.sendRequest,
			},
		},
	}

	err := main.Create()
	if err != nil {
		jklog.L().Fatal(err)
	}

	mw.Run()
}
